﻿$(function ()
{
    var hub = $.connection.gameHub;

    hub.client.gameFinished = function (cardId, winner, scoreOfWinner) 
    {
        $(function () 
        {
            $("<div title='Leik lokið!'>" + winner + " vann með " + scoreOfWinner + " stigum!  </div>").dialog(
                {
                    buttons:
                        {
                            Heim: function ()
                            {
                            window.location = '/Home';
                            }
                        }
               });
        });
    };

    hub.client.waitForUser2 = function ()
    {
        $(function ()
        {
            $("Beðið eftir því að fá mótspilara...").dialog(
                {
                });
        });
    };
    
    hub.client.player2Turn = function ()
    {
        $("#YourTurn1").css('visibility', 'hidden');
        $("#YourTurn2").css('visibility', 'visible');
    };

    hub.client.player1Turn = function ()
    {
        $("#YourTurn1").css('visibility', 'visible');
        $("#YourTurn2").css('visibility', 'hidden');
    };

    hub.client.player1Starts = function ()
    {
        $("#YourTurn1").css('visibility', 'visible');
    };

    hub.client.player2Starts = function ()
    {
        $("#YourTurn2").css('visibility', 'visible');
    };

    hub.client.showUpdateScore = function (user1Score, user2Score)
    {
        document.getElementById("ScoreUser1").innerHTML = user1Score;
        document.getElementById("ScoreUser2").innerHTML = user2Score;
    };

    hub.client.showUserOne = function (user1)
    {
        document.getElementById("SUser1").innerHTML = user1;
    };

    hub.client.showUserTwo = function (user2)
    {
        document.getElementById("SUser2").innerHTML = user2;
    };

    hub.client.showCard = function (cardId)
    {
        var buttonThatWasClicked = $("#" + cardId);
        buttonThatWasClicked.children().css('visibility', 'visible');
    };

    hub.client.hideCards = function (cardId)
    {
        var buttonThatWasClicked = $("#" + cardId);
        buttonThatWasClicked.children().css('visibility', 'hidden');
    };

    $.connection.hub.start().done(function ()
    {
        hub.server.join(group);
        hub.server.initialiseUsers(group); 

        $(".Button").click(function () {
            hub.server.clickCard(user, group, this.id);
        });
    });
});
